import { defineStore } from "pinia";
import {
  getDepartmentData,
  getRoleData,
  getAllMenusData,
  getCategoryData,
  getMenberData,
  getCarData,
} from "@/service/main/main";

interface Ia {
  [key: string]: any;
}
const useMainStore = defineStore("main", {
  state: (): Ia => ({
    showLoading: false,
    departmentData: [],
    roleData: [],
    allMenusData: [],
    categoryData: [],
    menberData: [],
    carData: [],
    // 菜单选中下标
    menu_tab_current: "",
    layoutConfig: {
      layoutMode: "Default",
      mainAnimation: "slide-right",
      // 是否暗黑模式
      isDark: false,
      /* 侧边菜单 */
      // 侧边菜单背景色
      menuBackground: ["#001529", "#1d1e1f"],
      // 侧边菜单文字颜色
      menuColor: ["#b7bdc3", "#CFD3DC"],
      // 侧边菜单激活项背景色
      menuActiveBackground: ["#0a60bd", "#1d1e1f"],
      // 侧边菜单激活项文字色
      menuActiveColor: ["#fff", "#3375b9"],
      // 侧边菜单顶栏背景色
      menuTopBarBackground: ["#00152905", "#1d1e1f"],
      // 侧边菜单宽度(展开时)，单位px
      menuWidth: 210,
      // 是否只保持一个子菜单的展开(手风琴)
      menuUniqueOpened: false,
      // 显示菜单栏顶栏(LOGO)
      menuShowTopBar: true,
      /* 顶栏 */
      // 顶栏文字色
      headerBarTabColor: ["#000000", "#CFD3DC"],
      // 顶栏激活项背景色
      headerBarTabActiveBackground: ["#ffffff", "#1d1e1f"],
      // 顶栏激活项文字色
      headerBarTabActiveColor: ["#000000", "#409EFF"],
      // 顶栏背景色
      headerBarBackground: ["#ffffff", "#1d1e1f"],
      // 顶栏悬停时背景色
      headerBarHoverBackground: ["#f5f5f5", "#18222c"],
    },
  }),
  actions: {
    // 获取角色数据和部门数据初始化就获取以便多个页面使用
    // 1.请求部门和角色数据在login那边初始化路由的时候顺便调用这个方法
    initRDdataAction() {
      this.getDepartmentDataAction();
      this.getCategoryDataAction();
      this.getRoleDataAction();
      this.getAllMenusDataAction();
      this.getMenberDataAction();
      this.getCarDataAction();
    },
    async getDepartmentDataAction() {
      const departmentResult = await getDepartmentData();
      this.departmentData.length = 0;
      this.departmentData.push(...departmentResult.data.list);
    },
    async getCategoryDataAction() {
      const categoryResult = await getCategoryData();
      this.categoryData.length = 0;
      this.categoryData.push(...categoryResult.data.list);
    },
    async getRoleDataAction() {
      const roleResult = await getRoleData();
      this.roleData.length = 0;
      this.roleData.push(...roleResult.data.list);
    },
    async getAllMenusDataAction() {
      const getAllMenusResult = await getAllMenusData();
      this.allMenusData.length = 0;
      this.allMenusData.push(...getAllMenusResult.data.list);
    },
    async getMenberDataAction() {
      const getMenberResult = await getMenberData();
      this.menberData.length = 0;
      this.menberData.push(...getMenberResult.data.list);
    },
    async getCarDataAction() {
      const getCarResult = await getCarData();
      this.carData.length = 0;
      this.carData.push(...getCarResult.data.list);
    },

    chageCurrentAction(current: string) {
      this.menu_tab_current = current;
    },
    getColorAction(name: any) {
      if (!this.layoutConfig.isDark) {
        return this.layoutConfig[name][0];
      } else {
        return this.layoutConfig[name][1];
      }
    },
  },
});

export default useMainStore;
